import json
import time
class BaseMsg():
    def __init__(self,jsonData:str):
        self.json=json.loads(jsonData)
        self.bot=int(self.json['bot'])
        self.time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(self.json['time']))
        self.type=self.json['type']
        self.subtype=self.json['subtype']
    def getInfo(self):
        print('bot:',self.bot)
        print('time:',self.time)
        print('type:',self.type)
        print('subtype:',self.subtype)

class FriendMsg(BaseMsg):
    def __init__(self,jsonData):
        super().__init__(jsonData)
        self.senderId=self.json['sender']['id']
        self.senderName=self.json['sender']['name']
        self.senderType=self.json['sender']['type']
        self.judgePic()
    def getInfo(self):
        super().getInfo()
        print('txt:',self.msgText)
        print('is pic:',self.pic)
        print('senderId:',self.senderId)
        print('senderName:',self.senderName)
        print('senderType:',self.senderType)
    def judgePic(self):
        if self.json['message']['text'][:4]=='[pic':
            self.pic=True
            self.picText=self.json['message']['text']
        else:
            self.pic=False
            self.msgText=self.json['message']['text']

class GroupMsg(BaseMsg):
    def __init__(self, jsonData):
        super().__init__(jsonData)
        self.picMsg=self.json['message']['text']
        self.groupId=self.json['group']['id']
        self.groupName=self.json['group']['name']
        self.senderId=self.json['sender']['id']
        self.senderName=self.json['sender']['name']
        self.senderTitle=self.json['sender']['title']
        self.senderAnonymous=self.json['sender']['anonymous']
        self.msgText=self.json['message']['text']





